package chatSystem;

import networkinterface.JavaNI;
import model.SharingFiles;
import model.SharingMessages;
import model.SystemState;
import model.Users;
import chatController.ChatController;
import chatGUI.ChatGUI;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;


/**
 * 
 * @author Pierre LUKJANENKO & Michael
 *
 */
public class ChatSystem {

	/*
	 * ATTRIBUTES
	 */
	/**
	 * User interface of the system
	 */
	private static ChatGUI chatGUI;
	/**
	 * Controller of the system
	 */
	private static ChatController controller;
	/**
	 * Model used to manage the local user and the remote users
	 */
	private static Users users;
	/**
	 * Model observable used to manage the sharing of messages
	 */
	private static SharingMessages sharingMessages;
	/**
	 * Model observable used to manage the sharing of files
	 */
	private static SharingFiles sharingFiles;
	/**
	 * Model used to manage the state of the system
	 */
	private static SystemState state;
	/**
	 * Network interface of the system
	 */
	private static JavaNI javaNI;
	
	/**
	 * Main of the application
	 * @param args
	 */
	public static void main(String[] args) {  
            
        try {
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (Exception e) {
            // If Nimbus is not available, you can set the GUI to another look and feel.
        }
            
        users = new Users();
        sharingMessages = new SharingMessages();
        sharingFiles = new SharingFiles();
        state = new SystemState();	
                
		controller = new ChatController(users, sharingMessages, sharingFiles, state);
		chatGUI = new ChatGUI(controller, users, state, sharingMessages, sharingFiles); 
		javaNI = new JavaNI(controller, users, sharingMessages, sharingFiles, state);
		
		users.addObserver(javaNI);
		users.addObserver(chatGUI);
		sharingMessages.addObserver(javaNI);
		sharingMessages.addObserver(chatGUI);
		sharingFiles.addObserver(javaNI);
		sharingFiles.addObserver(chatGUI);
		state.addObserver(chatGUI);
		state.addObserver(javaNI);
		controller.performOpenChat();
	}

}
